﻿using System;
using System.Collections.Generic;
using System.Linq;
using FoodEx.Domain.Entities;
using FoodEx.Domain.Entities.Enum;
using FoodEx.Domain.Repositories;

namespace FoodEx.Dal.Repositories
{
    //TODO: make this a real NhibernateRepository when we have a database with the necessary view
    public class DummyPatientRepository : IPatientRepository
    {
        private readonly IList<Patient> _patients;

        public DummyPatientRepository()
        {
            _patients = new List<Patient>
                           {
                               new Patient
                                   {
                                       Id = Guid.Parse("2fdaac87-10dc-4092-8f2c-1b29ae7aef3c"),
                                       PatientNumber = "1111111111",
                                       FamilyName = "Simpson",
                                       GivenName = "Homer",
                                       Sex = Gender.Male,
                                       BirthDate = new DateTime(1955, 5, 12),
                                       IsAbsent = true,
                                       PatientLocation = new PatientLocation
                                           {
                                               CareUnit = "800",
                                               Room = "3",
                                               Bed = "2"
                                           }
                                   },
                               new Patient
                                   {
                                       Id = Guid.Parse("faa44cf8-82c4-43ab-9403-008a97aa526f"),
                                       PatientNumber = "2222222222",
                                       FamilyName = "Simpson",
                                       GivenName = "Lisa",
                                       Sex = Gender.Female,
                                       BirthDate = new DateTime(1981, 9, 28),
                                       IsAbsent = false,
                                       PatientLocation = new PatientLocation
                                           {
                                               CareUnit = "800",
                                               Room = "3",
                                               Bed = "1"
                                           }
                                   },
                               new Patient
                                   {
                                       Id = Guid.Parse("a2b5e37c-c3ec-4dd1-8b4b-d633f65f537d"),
                                       PatientNumber = "333333333",
                                       FamilyName = "Simpson",
                                       GivenName = "Bart",
                                       Sex = Gender.Male,
                                       BirthDate = new DateTime(1980, 4, 1),
                                       IsAbsent = false,
                                       PatientLocation = new PatientLocation
                                           {
                                               CareUnit = "800",
                                               Room = "10",
                                               Bed = "1"
                                           }
                                   },
                               new Patient
                                   {
                                       Id = Guid.Parse("c24bbbc3-b95d-43fa-85c7-c3cb5f2d4274"),
                                       PatientNumber = "4444444444",
                                       FamilyName = "Gumble",
                                       GivenName = "Barney",
                                       Sex = Gender.Male,
                                       BirthDate = new DateTime(1950, 4, 1),
                                       IsAbsent = false,
                                       PatientLocation = new PatientLocation
                                           {
                                               CareUnit = "710",
                                               Room = "5",
                                               Bed = "2"
                                           }
                                   },
                               new Patient
                                   {
                                       Id = Guid.Parse("6bac83c8-b174-4671-8f8c-339b97ab02dd"),
                                       PatientNumber = "5555555555",
                                       FamilyName = "Skinner",
                                       GivenName = "Seymour",
                                       Sex = Gender.Male,
                                       BirthDate = new DateTime(1945, 4, 1),
                                       IsAbsent = false,
                                       PatientLocation = new PatientLocation
                                           {
                                               CareUnit = "710",
                                               Room = "15",
                                               Bed = "1"
                                           }
                                   },
                               new Patient
                                   {
                                       Id = Guid.Parse("0a3f410a-6e03-4132-9f13-59d756a69be4"),
                                       PatientNumber = "666666666",
                                       FamilyName = "Groundskeeper",
                                       GivenName = "Willie",
                                       Sex = Gender.Male,
                                       BirthDate = new DateTime(1947, 4, 1),
                                       IsAbsent = false,
                                       PatientLocation = new PatientLocation
                                           {
                                               CareUnit = "710",
                                               Room = "22",
                                               Bed = "1"
                                           }
                                   }
                           };
        }

        public IList<Patient> GetPatientBySearchTerm(string searchTerm)
        {
            return _patients
                .Where(x => x.FamilyName.Contains(searchTerm)
                            || x.GivenName.Contains(searchTerm)
                            || x.PatientNumber.Contains(searchTerm))
                .ToList();
        }

        public IList<Patient> GetPatientsByCareUnit(string careUnit)
        {
            return _patients.Where(x => x.PatientLocation.CareUnit == careUnit).ToList();
        }
    }
}